user www-data;
worker_processes 1;    # one(1) worker or equal the number of _real_ cpu cores. 4=4 core cpu
worker_priority 15;    # renice workers to reduce priority compared to system processes for
                       # machine health. worst case nginx will get ~25% system resources at nice=15
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ### Added ###
    ## see https://calomel.org/nginx.html
    # Timeouts, do not keep connections open longer then necessary to reduce
    # resource usage and deny Slowloris type attacks.
    client_body_timeout      5s; # maximum time between packets the client can pause when sending nginx any data
    client_header_timeout    5s; # maximum time the client has to send the entire header to nginx
    keepalive_timeout       75s; # timeout which a single keep-alive client connection will stay open
    send_timeout            15s; # maximum time between packets nginx is allowed to pause when sending the client data
    ### End Added ###

    ### Multiple Connection Attempts ### {{{
    ## http://nginx.org/en/docs/http/ngx_http_limit_req_module.html
    limit_req_zone $binary_remote_addr zone=perip:10m rate=1r/s;
    limit_req_zone $server_name zone=perserver:10m rate=10r/s;

### End Multiple Connection Attempts ### }}}

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    #####keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
